from time import sleep
from selenium import webdriver

driver = webdriver.Firefox()
url = 'https://www.baidu.com'
driver.get(url)
driver.find_element_by_id('kw').send_keys('163邮箱')
driver.find_element_by_id('su').click()
sleep(2)
driver.find_element_by_partial_link_text('163网易免费邮').click()
sleep(2)
driver.switch_to.window(driver.window_handles[-1])
iframe = driver.find_element_by_xpath('/html/body/div[2]/div[3]/div/div[3]/div[4]/div[1]/div[1]/iframe')
driver.switch_to.frame(iframe)
driver.find_element_by_name('email').send_keys('**')
driver.find_element_by_name('password').send_keys('**')
driver.find_element_by_id('dologin').click()
sleep(2)
driver.switch_to.default_content()
driver.find_element_by_id('_mail_component_24_24').click()
driver.find_element_by_class_name('nui-editableAddr-ipt').send_keys('***')
driver.find_elements_by_class_name('nui-ipt-input')[2].send_keys('数理系_科171班_刘晗  自动化发送邮件')
sleep(1)
iframe = driver.find_element_by_class_name('APP-editor-iframe')
driver.switch_to.frame(iframe)
driver.find_element_by_class_name('nui-scroll').send_keys('吃葡萄不吐葡萄皮！！！')
driver.switch_to.default_content()
driver.find_element_by_class_name('nui-ico-sent').click()
driver.quit()
